var app = getApp();
//获得

var MyRequest = require("../../utils/MyRequest.js");
var Global = require("../../Global.js");

Page({
  data:{
    cityId:1
  },
    //请求数据
    Presenter: {
        init: function (that) {
        var user = Global.getUserStorage();
        var data = { "action": "search", "key": that.data.inputValue,"cityId":that.data.cityId };
        MyRequest.MyGet("BuilderSearch", that, that.Binder.init, data);
        }
    },
    Binder:{
      init:function(result,that){
          that.setData({
            builders:result.data.data
          });
      }
    },
    toBack:function(event){
      var index = event.currentTarget.dataset.index;
      var pages = getCurrentPages();
      var currPage = pages[pages.length - 1];   //当前页面
      var prevPage = pages[pages.length - 2];  //上一个页面
      var builder = this.data.builders[index];
      //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
      prevPage.setData({
        company: builder.builderName ,
        builder:builder.id
      })

      wx.navigateBack();
    },
    bindKeyInput:function(e){
      this.setData({
        inputValue: e.detail.value
      })
      this.Presenter.init(this);
    },
    search:function(){
      this.Presenter.init(this);
    },
    onLoad:function(){
      var cityId = 1;
      
      if(Global.getCityId()){
      cityId=Global.getCityId()
    }else if (Global.getUserStorage().cityId){
      cityId=Global.getUserStorage().cityId;
    }
      this.setData({
        inputValue:"",
        cityId:cityId
      });
      console.log("城市Idd:"+this.data.cityId);
      
      this.Presenter.init(this);
    }
});